<?php


class Views {

	private $code			= '';
	private $tags			= array();
	private $error			= FALSE;
	private $pathError404	= '/core-application/error_page/error404.html';

	public function __construct($file, $t) {
		
		if( ! empty($file) )
		{
			$this -> code = file_get_contents($file);
			
			if( ! empty($t))
				$this -> tags = $t;
			
		} else {
			$this -> code = file_get_contents($this -> pathError404);
			$this -> error = TRUE;
		}
		
	}

	private function replaceTag() {
		
		if(($this -> error !== TRUE) || count($this -> tags) > 0)
		{
			foreach($this -> tags as $key => $value)
			{
				$this -> code = str_replace("{code}" . $key . "{/code}", $value, $this -> code);
			}
		}
		
	}

	public function showView() {
		if($this -> error !== TRUE)
		{
			$this -> replaceTag();
				echo $this -> code;
		} else {
			echo $this -> error;
		}
	}

	function __destruct() {
		
		$this -> code	= '';
		$this -> tags	= array();
		$this -> error	= FALSE;
		
	}

}


?>